/* eslint-disable no-undef */
export function debounce(fn, delay) {
  let timer = null
  return function (...args) {
    let context = this
    if (timer) clearTimeout(timer)
    timer = setTimeout(function () {
      fn.apply(context, args)
    }, delay)
  }
}

function isObject(x) {
  return Object.prototype.toString.call(x) === '[object Object]';
}

export function cloneDeep(obj, hash = new Map()) {
  if (!isObject(obj)) return obj;
  if (hash.has(obj)) return hash.get(obj);
  var target = Array.isArray(obj) ? [] : {};
  hash.set(obj, target);
  for (let key in obj) {
    if (obj.hasOwnProperty(key)) {
      if (isObject(obj[key])) {
        target[key] = cloneDeep(obj[key], hash);
      } else {
        target[key] = obj[key];
      }
    }
  }
  return target;
}

export function formatTime(time) {
  let date = new Date(Number(time + '000'));
  return date.getFullYear() + '.' + (date.getMonth() + 1) + '.' + date.getDate();
}